﻿using System;
using System.Linq;

namespace MusicPlayer
{
    abstract class Driver : IDriverCommands
    {
        public virtual DriverState State
        {
            get;
            protected set;
        }

        public abstract void Play(string fileToPlay);

        public abstract void Pause();

        public abstract void Stop();

        public abstract void SetVolume(double volume);

        public abstract void Mute();

        public event EventHandler OnMediaEnd;

        protected virtual void MediaEnded(EventArgs args)
        {
            if (OnMediaEnd != null)
            {
                OnMediaEnd(this, args);
            }
        }

        public event EventHandler<DriverStateArgs> OnStateChange;

        protected virtual void StateChanged(DriverStateArgs args)
        {
            if (OnStateChange != null)
            {
                OnStateChange(this, args);
            }
        }

        public event EventHandler<DriverTimeArgs> OnTimeChange;

        protected virtual void TimeChanged(DriverTimeArgs args)
        {
            if (OnTimeChange != null)
            {
                OnTimeChange(this, args);
            }
        }

        public event EventHandler<DriverMediaLocationArgs> OnMediaLocationChange;

        protected virtual void MediaLocationChanged(DriverMediaLocationArgs args)
        {
            if (OnMediaLocationChange != null)
            {
                OnMediaLocationChange(this, args);
            }
        }
    }

    public class DriverStateArgs : EventArgs
    {
        public DriverState State
        {
            get;
            protected set;
        }

        public DriverStateArgs(DriverState state)
        {
            this.State = state;
        }
    }

    public class DriverTimeArgs : EventArgs
    {
        public TimeSpan Time
        {
            get;
            protected set;
        }

        public DriverTimeArgs(TimeSpan time)
        {
            this.Time = time;
        }
    }

    public class DriverMediaLocationArgs : EventArgs
    {
        public string Location
        {
            get;
            protected set;
        }

        public DriverMediaLocationArgs(string location)
        {
            this.Location = location;
        }
    }
}
